﻿Ext.define('app.prm.detail.TeamEvaluation',
{
    extend: 'Ext.window.Window',
    border: true,
    title: '成员评价',
    modal: true,
    shadow: true,
    maximized: true,
    autoScroll: true,
    //layout: 'fit',
    bodyStyle: 'padding:20px',
    projectId: 0,
    teamCommentStatus: 10,
    initComponent: function () {
        var me = this;
        this.items = [
            {
                xtype: 'form',
                border: false,
                items: []
            }
        ];
        this.buttons = [
            {
                text: '保存',
                handler: function () { me.saveComment(10); }, scope: this
            },
            {
                text: '提交',
                hidden: me.teamCommentStatus == 20,
                handler: function () { me.saveComment(20); }, scope: this
            },
            {
                text: '取消',
                handler: function () { this.close(); }, scope: this
            }
        ];
        me.callParent();
    },
    listeners: {
        afterrender: function (me) {
            me.componentInit();
        }
    },
    componentInit: function () {
        var me = this;

        App.AjaxGet('/api/services/app/project/GetTeamComment?projectId=' + me.projectId, function (data) {
            console.log("---------------------------------------------------------");
            console.log(data);
            console.log("---------------------------------------------------------");
            for (var i = 0; i < data.result.length; i++) {
                var record = data.result[i];
                var panel = new Ext.panel.Panel(
                {
                    border: false,
                    items: [
                        { xtype: 'displayfield', value: record.userName + '(' + record.roleName + ')' },
                        { xtype: 'hidden', name: 'Id', value: record.Id },
                        { xtype: 'hidden', name: 'UserId', value: record.UserId },
                        { xtype: 'hidden', name: 'ProjectRoleId', value: record.ProjectRoleId },
                        new Ext.form.RadioGroup(
                        {
                            items: [
                                { boxLabel: '1分', inputValue: '1', checked: record.score == 1 },
                                { boxLabel: '2分', inputValue: '2', checked: record.score == 2 },
                                { boxLabel: '3分', inputValue: '3', checked: record.score == 3 },
                                { boxLabel: '4分', inputValue: '4', checked: record.score == 4 },
                                { boxLabel: '5分', inputValue: '5', checked: record.score == 5 }
                            ]
                        }),
                        {
                            xtype: 'textarea',
                            height: 150,
                            width: 700,
                            name: 'Content',
                            emptyText: '请输入评价内容',
                            value: record.content
                        }
                    ]
                });
                me.down('form').add(panel);
            }
        });
    },
    saveComment: function (status) {
        var me = this;
        var formValue = me.down('form').getForm().getValues();
        console.log("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
        console.log(formValue);
        console.log("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");

        formValue.Status = status;
        App.AjaxPost('/api/services/app/projectRole/UpdateTeamComment', formValue, function ()
        {

        });

    }
});